"""
json格式解析器
"""
from langchain_core.output_parsers import JsonOutputParser
from langchain_core.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate

from models import get_ds_model_client

messages = ChatPromptTemplate.from_messages([SystemMessagePromptTemplate.from_template("你是一个专业的程序员"),
                                             HumanMessagePromptTemplate.from_template("{input}")])
client = get_ds_model_client()
parser = JsonOutputParser()

chain = messages | client | parser
print(chain.invoke({"input": "langchain是什么? 问题用question 回答用ans 返回一个JSON格式"}))